// Origin
//import UIKit
//import Flutter
//
//@UIApplicationMain
//@objc class AppDelegate: FlutterAppDelegate {
//  override func application(
//    _ application: UIApplication,
//    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
//  ) -> Bool {
//    GeneratedPluginRegistrant.register(with: self)


//         if #available(iOS 10.0, *) {
//           UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
//         }

//    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
//  }
//}


// // opt 2
// import UIKit
// import Flutter
// import Pushy
// import Firebase
// import FirebaseMessaging
// import FirebaseAuth
// import UserNotifications
// import FirebaseInstanceID


// @UIApplicationMain
// @objc class AppDelegate: FlutterAppDelegate {
//  override func application(
//    _ application: UIApplication,
//    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
//  ) -> Bool {
//        print("init")
//        FirebaseApp.configure()
//        GeneratedPluginRegistrant.register(with: self)
//     if #available(iOS 10.0, *) {
//              UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
//    }
//    application.registerForRemoteNotifications()

//        return super.application(application, didFinishLaunchingWithOptions: launchOptions)

//  }
//   //  override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//   //      let firebaseAuth = Auth.auth()
//   //      firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
//   //      return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)

//   //  }

//   // override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
//   //    let pushy = Pushy(UIApplication.shared)
//   //    pushy.application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)

//   //    let firebaseAuth = Auth.auth()
//   //    firebaseAuth.canHandleNotification(userInfo);
    
//   //    return
//   //  }   
// // ---- old ---- //

// // APNs has assigned the device a unique token
// override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//     // Call internal Pushy SDK method
//     Pushy.shared?.application(application, didRegisterForRemoteNotificationsWithDeviceToken:deviceToken)
//     // let firebaseAuth = Auth.auth()
//     // firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
//     // return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
 
//     // Pass token to Firebase SDK
//     Messaging.messaging().apnsToken = deviceToken
    
// }

// // APNs failed to register the device for push notifications
// override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
//     // Call internal Pushy SDK method
//     Pushy.shared?.application(application, didFailToRegisterForRemoteNotificationsWithError:error)
// }
//    // Device received notification (legacy callback)
// override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
//     // Call internal Pushy SDK method
//     Pushy.shared?.application(application, didReceiveRemoteNotification:userInfo)

//     // With swizzling disabled you must let Messaging know about the message, for Analytics
//     Messaging.messaging().appDidReceiveMessage(userInfo)
//     // let firebaseAuth = Auth.auth()
//     // firebaseAuth.canHandleNotification(userInfo);
// }

// // Device received notification (with completion handler)
// override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
//     // Call internal Pushy SDK method
//     Pushy.shared?.application(application, didReceiveRemoteNotification:userInfo, fetchCompletionHandler: completionHandler)

//     // With swizzling disabled you must let Messaging know about the message, for Analytics
//     Messaging.messaging().appDidReceiveMessage(userInfo)
//     // let firebaseAuth = Auth.auth()
//     // firebaseAuth.canHandleNotification(userInfo);
// }
// //    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

// //        let firebaseAuth = Auth.auth()
// // //    userInfo["com.google.firebase.auth"] != nil ) {
// //     if (firebaseAuth.canHandleNotification(userInfo)) {
// //         completionHandler(.noData)
// //         return
// //     }
// //       return super.application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
// //    }


// }







// ------ //
// // opt 2
import UIKit
import Flutter
import Pushy
import Firebase
import FirebaseAuth
import UserNotifications
//import FirebaseInstanceID


@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
 override func application(
   _ application: UIApplication,
   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
 ) -> Bool {
       print("init")
       FirebaseApp.configure()
       GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
               print("mark11")
             UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
   }
   application.registerForRemoteNotifications()

       return super.application(application, didFinishLaunchingWithOptions: launchOptions)

 }
   override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
       let firebaseAuth = Auth.auth()
       firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)


       return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)

   }

  override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
     let pushy = Pushy(UIApplication.shared)
     pushy.application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)

     let firebaseAuth = Auth.auth()
     firebaseAuth.canHandleNotification(userInfo);
    
     return

   }  
}   
